﻿using System.Collections.Generic;
using ModelLayer.Common.GoogleMap;
using ServiceAccessLayer.Infrastructure;

namespace ServiceAccessLayer.GoogleMap
{
    public class GoogleMapRepository : BaseRepository
    {
        public GoogleMapRepository(List<KeyValuePair<string, IEnumerable<string>>> extraDataAsHeader)
            : base(extraDataAsHeader)
        {
        }

        public GeoCode GetLatLong(string locationStr)
        {
            //Extra Data
            //ExtraDataAsHeader.Add(new KeyValuePair<string, IEnumerable<string>>("moduleName", new List<string> { "Admin" }));

            //string serviceAutoCompanyStatus = ServiceMessageConstant.Ok;

            GeoCode geoCode;
            try
            {
                using (GenericRestHttpClient<GeoCode, string> memberClient = new GenericRestHttpClient<GeoCode, string>("http://maps.google.com", "/maps/api/geocode/json?address=" + locationStr, ExtraDataAsHeader))
                {
                    geoCode = AsyncContext.Run(() => memberClient.GetAsync());
                }
            }
            catch (System.Exception ex)
            {
                geoCode = new GeoCode();
                //serviceAutoCompanyStatus = ServiceMessageConstant.Error;
            }

            return geoCode;
        }
    }
}
